package com.prd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.prd.config.LoginInterceptor;
import com.prd.dto.OaEmployeeDTO;
import com.prd.enums.OaOfferLetterStatusTpyeEnum;
import com.prd.model.LoginUser;
import com.prd.model.OaEmployeeDO;
import com.prd.mapper.OaEmployeeMapper;
import com.prd.service.OaEmployeeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.util.CommonUtil;
import com.prd.util.JsonData;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 员工数据表 服务实现类
 * </p>
 *
 * @author lizhaoyi
 * @since 2023-12-12
 */
@Service
@Slf4j
public class OaEmployeeServiceImpl extends ServiceImpl<OaEmployeeMapper, OaEmployeeDO> implements OaEmployeeService {

    @Autowired
    private OaEmployeeMapper oaEmployeeMapper;

    /**
     * 查询花名册
     * @param dept
     * @param conditionStr
     * @return
     */
    @Override
    public JsonData selectByCondition(String dept, String conditionStr) {
        //匹配单个条件
        List<OaEmployeeDO> oaEmployeeDOList = new ArrayList<>();
        if (StringUtils.isNotBlank(dept) && StringUtils.isBlank(conditionStr)) {
            OaEmployeeDO oaEmployeeDO = oaEmployeeMapper.selectOne(new LambdaQueryWrapper<OaEmployeeDO>().eq(OaEmployeeDO::getDept, dept));
            oaEmployeeDOList.add(oaEmployeeDO);
        }

        if (StringUtils.isBlank(dept) && StringUtils.isNotBlank(conditionStr)) {
            //模糊查询匹配名字条件
            OaEmployeeDO oaEmployeeDOByName = oaEmployeeMapper.selectOne(new LambdaQueryWrapper<OaEmployeeDO>().like(OaEmployeeDO::getName, conditionStr));
            if (oaEmployeeDOByName == null) {
                //模糊查询匹配电话条件
                OaEmployeeDO oaEmployeeDOByTelephone = oaEmployeeMapper.selectOne(new LambdaQueryWrapper<OaEmployeeDO>().like(OaEmployeeDO::getTelephone, conditionStr));
                oaEmployeeDOList.add(oaEmployeeDOByTelephone);
            }else {
                oaEmployeeDOList.add(oaEmployeeDOByName);
            }
        }
        //匹配多个条件
        if (StringUtils.isNotBlank(dept) && StringUtils.isNotBlank(conditionStr)) {
            OaEmployeeDO oaEmployeeDOByName = oaEmployeeMapper.selectOne(new LambdaQueryWrapper<OaEmployeeDO>().eq(OaEmployeeDO::getDept, dept).like(OaEmployeeDO::getName, conditionStr));
            if (oaEmployeeDOByName == null) {
                OaEmployeeDO oaEmployeeDOByTelephone = oaEmployeeMapper.selectOne(new LambdaQueryWrapper<OaEmployeeDO>().like(OaEmployeeDO::getTelephone, conditionStr));
                oaEmployeeDOList.add(oaEmployeeDOByTelephone);
            }else {
                oaEmployeeDOList.add(oaEmployeeDOByName);
            }
        }

        return JsonData.buildSuccess(oaEmployeeDOList);
    }


}
